package org.emmannuel.virtues.client.panel;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Label;

public class MainPanel extends HorizontalPanel {

	Hyperlink hyperHome = new Hyperlink("Home", "Home");
	Hyperlink hyperAdopt = new Hyperlink("What's going here?", "Adopting");
	Hyperlink hyperAccount = new Hyperlink("Account", "Account");
	Hyperlink hyperAbout = new Hyperlink("About", "About");
	final private AboutVirtuePanel avp;

	public MainPanel(final AboutVirtuePanel avp) {
		this.avp = avp;
		addStyleName("main-panel");
		setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		hyperHome.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				avp.setVisible(false);
			}
		});
		add(hyperHome);
		add(hyperAdopt);
		hyperAdopt.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				DialogBox db = new DialogBox(true, true);
				db.setText("What's going here?");
				db.setWidget(new Label(
						"Here will be animation, youtube video..."));
				db.center();
			}
		});
		add(hyperAccount);
		hyperAccount.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				showAccountInformation();
			}
		});
		add(hyperAbout);
		hyperAbout.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				Window.open("http://www.ice-net.org/", "About Save a day", "");
			}
		});
	}

	private void showAccountInformation() {
		if (!AccountPanel.isOnline()) {
			AccountPanel.login();
		} else {
			AccountPanel.showAccount();
		}
	}
}
